﻿using System;
using System.Windows.Forms;

namespace XCI.Extensions
{
    public static class FormExtensions
    {
        public static void ShowDialogOk(this Form frm, Action callback = null)
        {
            var result = frm.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                callback?.Invoke();
            }
            frm.Dispose();
        }

        public static void ShowDialogCancel(this Form frm, Action callback = null)
        {
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                callback?.Invoke();
            }
            frm.Dispose();
        }

        public static void ShowDialogCallback(this Form frm, Action okCallback, Action cancelCallback)
        {
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                okCallback?.Invoke();
            }
            else
            {
                cancelCallback?.Invoke();
            }
            frm.Dispose();
        }
    }
}
